package com.ldzy.controller;


import com.ldzy.pojo.MyResponse;
import com.ldzy.pojo.ResultCode;
import com.ldzy.pojo.TransferVO;
import com.ldzy.pojo.User;
import com.ldzy.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

@RequestMapping("user")
@RestController
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("transfer")
    @ResponseBody
    public MyResponse transfer(@RequestBody TransferVO transferVO){
        log.debug("这是debug信息");//就是System.out.println("hello");
        log.info("这是info信息");
        User inner = transferVO.getInner();
        User outer = transferVO.getOuter();
        Double money = transferVO.getMoney();
        boolean flag = userService.transfer(outer, inner, money);
        if (flag==true){
            MyResponse<Object> myResponse = new MyResponse<>(ResultCode.SUCCESS_TRANSFER);
            return myResponse;
        }else {
            MyResponse<Object> myResponse = new MyResponse<>(ResultCode.ERROR_TRANSFER);
            return myResponse;
        }
    }


    @PostMapping("add")
    public MyResponse add(@RequestBody User user){
        System.out.println("hello");
        MyResponse myResponse = new MyResponse(ResultCode.SUCCESS);
        myResponse.setData(user);
        return myResponse;
    }

    @GetMapping("del")
    public MyResponse del(){
        return null;
    }

}
